define(function (require, exports, module) {
	var $ = require('../../libs/jquery.min.js');
	var cards = require('../controllers/card.js');
	var health = require('../controllers/health.js');
	var funs = require('../controllers/king.js');
	seajs.use('./css/style.css');

	// Opponent Round
	// Your Round

	// 模板
	var body = $('body');

	var html = '';
	html += '<div class="table">';
	html += '	<div class="rival">';
	html += '		<div class="userName">DevSpeed</div>';
	html += '		<div class="number">0/21</div>';
	html += '	</div>';
	html += '	<div class="limit"></div>';
	html += '	<div class="user">';
	html += '		<div class="userName">DevSpeed</div>';
	html += '		<div class="number">0/21</div>';
	html += '	</div>';
	html += '</div>';

	var table = $(html);

	// 点数计算
	var Point = 21;
	var writePoint = function (num, str) {
		var element = table.find('.' + str + ' .number');
		element.text(num + '/' + Point);
		if (num > Point) {
			element.css('color', 'rgb(255, 58, 58)');
		} else if (num == Point) {
			element.css('color', 'rgb(22, 201, 201)');
		} else {
			element.css('color', '#fff');
		}
	};

	var mainPoint = function (num) {
		writePoint(num, 'user');
	};
	var rivalPoint = function (num) {
		writePoint(num, 'rival');
	};

	// 回合
	var round = function (roundName) {
		var html = $('<div class="round TA" style="background-image:url(\'./img/round/' + roundName + '.png\')"></div>');
		body.append(html);
		setTimeout(function () {
			html.css('width', '600px');
		}, 20);
		setTimeout(function () {
			html.css('width', '0px');
			setTimeout(function () {
				html.remove();
			}, 501);
		}, 2000);
	};


	// 牌组

	var mainCards = cards();
	var rivalCards = cards();
	table.find('.user').append(mainCards.render());
	table.find('.rival').append(rivalCards.render());

	mainCards.setCard(6);
	mainPoint(mainCards.getNums());

	setTimeout(function () {

		mainCards.setCard(2);
		mainPoint(mainCards.getNums());
	}, 1000);


	rivalCards.setCard(0);
	rivalPoint(rivalCards.getNums());

	// rivalCards.setCard(11);
	// rivalPoint(rivalCards.getNums());

	// rivalCards.setCard(10);
	// rivalPoint(rivalCards.getNums());

	// rivalCards.setCard(7);
	// rivalPoint(rivalCards.getNums());

	// setTimeout(function () {
	// 	rivalCards.back();
	// 	rivalPoint(rivalCards.getNums(4));
	// }, 2000);


	// 生命

	var mainHealth = health();
	var rivalHealth = health();
	table.find('.user').append(mainHealth.render());
	table.find('.rival').append(rivalHealth.render());


	// setTimeout(function () {
	// 	mainHealth.hit(3);
	// 	setTimeout(function () {
	// 		mainHealth.minus(3);
	// 	}, 2000);
	// }, 2000);


	// 按钮
	var buttons = $('<div class="buttons"></div>');
	var more = $('<div class="button">要一张牌</div>');
	var noMore = $('<div class="button">不要牌</div>');
	buttons.append(more).append(noMore);

	// 提示信息
	var message = $('<div class="message"></div>');


	// 对手王卡
	var rivalKings = funs.kings(message);



	// 物品栏
	var mainKings = funs.kings(message);
	var Inventory = funs.Inventory(mainKings, message);

	Inventory.appendKing('attack');
	Inventory.appendKing('attack+');
	Inventory.appendKing('attack++');

	// 使用牌组

	table.find('.user').append(mainKings.render());
	table.find('.rival').append(rivalKings.render());


	rivalKings.append('attack');
	rivalKings.append('attack+');
	rivalKings.append('attack++');

	//渲染
	body.append(table);
	body.append(buttons);

	body.append(Inventory.render());
	body.append(message);



	// round('main');
	// setTimeout(function () {
	// 	round('rival');
	// }, 3000);



	// body.append(mark);
});